#include "BuildUnit.h"

#include "Task.h"

namespace BroodWar
{
	namespace Addon
	{
		BuildUnit^ ConvertBuildUnit(BWSAL::BuildUnit* unit)
		{
			if(unit == NULL)
				return nullptr;
			return gcnew BuildUnit(unit);
		}
		
		BWSAL::BuildUnit* ConvertBuildUnit(BuildUnit^ unit)
		{
			if(unit == nullptr)
				return NULL;
			return unit->instance;
		}

		BuildUnit::BuildUnit(BWSAL::BuildUnit* unit)
		{
			instance = unit;
			dispose = false;
		}

		BuildUnit::~BuildUnit()
		{
			if(dispose)
				delete instance;
		}

		BuildUnit::!BuildUnit()
		{
			if(dispose)
				delete instance;
		}
		
		BuildUnit::BuildUnit(Addon::Task^ task)
		{
			instance = new BWSAL::BuildUnit(ConvertTask(task));
			dispose = true;
		}
		
		BuildUnit::BuildUnit(Api::Unit^ unit)
		{
			instance = new BWSAL::BuildUnit(Api::ConvertUnit(unit));
			dispose = true;
		}

		BuildUnit^ BuildUnit::BuilderUnit::get()
		{
			return ConvertBuildUnit(instance->getBuildUnit());
		}
		
		Build^ BuildUnit::Type::get()
		{
			return ConvertBuild(instance->getType());
		}

		void BuildUnit::SetUnit(Api::Unit^ unit)
		{
			instance->setUnit(ConvertUnit(unit));
		}
		
		void BuildUnit::SetTask(Addon::Task^ task)
		{
			instance->setTask(ConvertTask(task));
		}
		
		bool BuildUnit::IsReal::get()
		{
			return instance->isReal();
		}
		
		Api::Unit^ BuildUnit::Unit::get()
		{
			return ConvertUnit(instance->getUnit());
		}
		
		Addon::Task^ BuildUnit::Task::get()
		{
			return ConvertTask(instance->getTask());
		}
			
		BuildUnit^ BuildUnit::GetBuildUnit(Api::Unit^ unit)
		{
			return ConvertBuildUnit(BWSAL::BuildUnit::getBuildUnit(ConvertUnit(unit)));
		}
		
		BuildUnit^ BuildUnit::GetBuildUnitIfExists(Api::Unit^ unit)
		{
			return ConvertBuildUnit(BWSAL::BuildUnit::getBuildUnitIfExists(ConvertUnit(unit)));
		}
		
		void BuildUnit::SetBuildUnit(Api::Unit^ unit, BuildUnit^ buildUnit)
		{
			BWSAL::BuildUnit::setBuildUnit(ConvertUnit(unit), ConvertBuildUnit(buildUnit));
		}
	}
}


/*
#pragma once
#include "BWSAL/BuildType.h"
#include "BWSAL/MetaUnit.h"
namespace BWAPI
{
  class Unit;
}
namespace BWSAL
{
  class Task;
  class BuildUnit : public MetaUnit
  {
    public:
      virtual BuildUnit* getBuildUnit();
      virtual BuildType getType() const;
      BuildUnit( Task* task );
      BuildUnit( BWAPI::Unit* unit );
      void setUnit( BWAPI::Unit* unit );
      void setTask( Task* task );
      bool isReal() const;
      BWAPI::Unit* getUnit() const;
      Task* getTask() const;
      static BuildUnit* getBuildUnit( BWAPI::Unit* unit );
      static BuildUnit* getBuildUnitIfExists( BWAPI::Unit* unit );
      static void setBuildUnit( BWAPI::Unit* unit, BuildUnit* buildUnit );
      struct state
      {
        int m_availableSince;
        BuildType m_type;
        int m_nextLarvaSpawnTime;
        int m_larvaCount;
        BuildType m_addon;
      };
      state m_currentState;
      state m_planningData;
    private:
      void initializeInformation();
      BWAPI::Unit* m_unit;
      Task* m_task;
  };
}
*/